package top.healthylife.gateway.platform.td.api.api.creditbodyguard;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.healthylife.gateway.core.service.ParentFace;
import top.healthylife.gateway.dto.annotation.ApiServiceExplain;
import top.healthylife.gateway.platform.td.api.utils.TdUtils;
import top.healthylife.gateway.platform.td.dto.creditbodyguard.relationrisk.req.TdReqRelationRiskDto;
import top.healthylife.gateway.platform.td.dto.creditbodyguard.relationrisk.res.TdResRelationRiskDto;

import java.util.Collections;

/**
 * @author : GaoZeXi
 * @date 2021/7/28 9:48
 */
@Slf4j
@Service
@ApiServiceExplain(price = 20, apiName = "知识图谱关联风险分", info = "信贷保镖紧密围绕客户的业务和风控需求，为银行信用卡、现金贷、消费金融、汽车金融等各行各业的客户提供全生命周期的一站式定制服务，并采用项目模式提供咨询、数据、产品、运营等协同服务。全力协助客户在保证业务质量的同时提高业务效率，规避业务风险，最终实现盈利目标。")
public class TdBusinessFlowRelationRiskApi implements ParentFace<TdReqRelationRiskDto, TdResRelationRiskDto> {
    static final String URL = "/bodyguard/apply/v5";
    static final String METHOD = "POST";
    static final String BIZ_CODE = "jck_jck_glfxf";
    @Override
    public TdResRelationRiskDto execute(TdReqRelationRiskDto t) throws Exception {
        JSONObject jsonObject = TdUtils.tongDunHttpRequest(t, URL, METHOD, BIZ_CODE);
        JSONObject result_desc = jsonObject.getJSONObject("result_desc");
        if(result_desc==null){
            return new TdResRelationRiskDto();
        }
        JSONObject antifraudLinkanalysis = result_desc.getJSONObject("ANTIFRAUD_LINKANALYSIS");
        if(antifraudLinkanalysis==null){
            return new TdResRelationRiskDto();
        }
        Object o = antifraudLinkanalysis.get("detail");
        if(o==null){
            return new TdResRelationRiskDto();
        }
        if(o.toString().equals("查询无结果")){
            antifraudLinkanalysis.put("detail", Collections.emptyList());
            antifraudLinkanalysis.put("detailDesc", "查询无结果");
        }
        return jsonObject.toJavaObject(TdResRelationRiskDto.class);
    }
}
